import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/application/double_prevention_page/risk_control_page/task_implementation_page/task_details_page/task_details_controller.dart';

/// 风险管控清单详情 措施详情
class TaskDetailsPage extends StatelessWidget {
  TaskDetailsPage({super.key});

  final controller = Get.put(TaskDetailsController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.bg_color_grey,
      appBar: CustomAppBar(
        titleText: '风险管控清单',
        actions: [TextButton(onPressed: () {}, child: const Text('台账'))],
      ),
      body: GetBuilder(
          init: controller,
          builder: (_) {
            return SingleChildScrollView(
              child: Column(
                children: [
                  _titleBg(),
                  Container(
                    height: 40.w,
                    width: double.infinity,
                    color: const Color(0xFFF4F7FF),
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.only(left: 40.w),
                    child: Text(
                      '风险分析对象名称：${controller.data?.riskObjectName??''}',
                      style: TextStyle(
                        fontSize: 16.sp,
                      ),
                    ),
                  ),
                  Container(
                    height: 1.w,
                    color: const Color(0xFFDEE5FD),
                  ),
                  Container(
                    height: 50.w,
                    color: Colors.white,
                    child: Row(
                      children: [
                        Expanded(child: _title('责任部门:', controller.data?.objectHazardDep??'')),
                        Expanded(child: _title('责任人:', controller.data?.objectHazardLiablePerson??'')),
                      ],
                    ),
                  ),
                  _titleBg(),
                  Container(
                    color: Colors.white,
                    child: Column(
                      children: [
                        AppGaps.vGap16,
                        _title('风险分析单元名称:', controller.data?.riskUnitName??''),
                        Row(
                          children: [
                            Expanded(child: _title('责任部门:', controller.data?.unitHazardDep??'')),
                            Expanded(child: _title('责任人:', controller.data?.unitHazardLiablePerson??'')),
                          ],
                        ),
                        AppGaps.vGap8,
                      ],
                    ),
                  ),
                  _titleBg(),
                  Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(top: 20.w, bottom: 20.w),
                    child: Column(
                      children: [
                        _title('风险事件名称:', controller.data?.riskEventName??''),
                        _title('初始后果:', '${controller.data?.initialRiskConsequences??''}'),
                        _title('初始可能性:', '${controller.data?.initialRiskPossibility??''}'),
                        _title('初始风险度:', '${controller.data?.initialRiskDegree??''}'),
                        _title('初始风险等级:', '${_initialRiskLevel(controller.data?.initialRiskLevel)}'),
                      ],
                    ),
                  ),
                  _titleBg(),
                  Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(top: 20.w, bottom: 20.w),
                    child: Column(
                      children: [
                        _title('管控措施描述:', controller.data?.riskMeasureDesc??''),
                        _title('管控手段:', controller.data?.dataSrc??''),
                        _title('管控措施层级:', controller.data?.riskMeasureLevel??''),
                        _title('隐患排查条目:', controller.data?.troubleshootContent??''),
                        _title('管控措施分类1:', controller.data?.classify1??''),
                        _title('管控措施分类2:', '${controller.data?.classify2??''}'),
                        _title('管控措施分类3:', controller.data?.classify3??''),
                        _title('后果降低值:', '${controller.data?.consequenceReduction??''}'),
                        _title('可能性降低值:', '${controller.data?.probabilityReduction??''}'),
                      ],
                    ),
                  ),
                  _titleBg(),
                  Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(top: 20.w, bottom: 20.w),
                    child: Column(
                      children: [
                        _title('创建人:', controller.data?.createBy??''),
                        _title('最后修改人:', controller.data?.updateBy??''),
                        _title('创建时间:', controller.data?.createDate??''),
                      ],
                    ),
                  ),
                ],
              ),
            );
          }),
    );
  }

  /// 标题背景分隔栏
  Widget _titleBg() {
    return Column(
      children: [
        AppGaps.vGap12,
        Container(
          height: 2.w,
          color: const Color(0xFF587DF5),
        ),
      ],
    );
  }

  Widget _title(String title, String? value) {
    return Container(
      padding: EdgeInsets.only(top: 8.w, bottom: 8.w),
      child: Row(
        children: [
          AppGaps.hGap40,
          Text(
            title,
            style: TextStyle(
              color: Colors.black,
              fontSize: 12.sp,
            ),
          ),
          if (value != null)
            Expanded(
                child: Text(
              value,
              style: TextStyle(
                color: const Color(0xFF7C7D93),
                fontSize: 12.sp,
              ),
            )),
        ],
      ),
    );
  }

  ///初始风险等级：1_重大2_较大3_一般4_低
  _initialRiskLevel(String? initialRiskLevel) {
    if (initialRiskLevel == '1') {
      return '重大风险';
    } else if (initialRiskLevel == '2') {
      return '较大风险';
    } else if (initialRiskLevel == '3') {
      return '一般风险';
    } else {
      return '低风险';
    }
  }
}
